#!/usr/bin/env python3
"""
测试最终修复版本
"""
import asyncio
from pathlib import Path
from app.services.large_video_analyzer_fixed import LargeVideoAnalyzerFixed

async def test_final_fix():
    """测试最终修复版本"""
    try:
        print("🧪 测试最终修复版本...")
        
        # 找到测试视频
        uploads_dir = Path("uploads")
        video_files = list(uploads_dir.glob("*.mp4"))
        
        if not video_files:
            print("❌ 没有找到测试视频")
            return False
        
        test_video = video_files[0]
        print(f"📹 使用测试视频: {test_video.name}")
        
        # 初始化修复版分析器
        analyzer = LargeVideoAnalyzerFixed()
        
        # 执行分析
        result = await analyzer.analyze_large_video(
            video_path=test_video,
            prompt="请简单描述这个视频",
            split_method="duration",
            segment_duration=60,
            max_segments=3,
            analysis_mode="sequential",
            min_segment_duration=10
        )
        
        print("✅ 分析完成!")
        print(f"📊 结果类型: {result.get('type', 'unknown')}")
        
        if result.get('success') == False:
            print(f"❌ 分析失败: {result.get('error', 'unknown')}")
            return False
        
        print(f"📊 片段数量: {result.get('segment_count', 0)}")
        print(f"📊 成功分析: {result.get('successful_segments', 0)}")
        print(f"📊 离线模式: {result.get('offline_mode', False)}")
        
        if result.get('overall_summary'):
            summary = result['overall_summary']
            print(f"📝 整体摘要: {summary[:150]}...")
        
        # 显示关键洞察
        if result.get('key_insights'):
            insights = result['key_insights']
            print(f"🔍 关键洞察:")
            for key, values in insights.items():
                if values:
                    print(f"   {key}: {values[:2]}")  # 只显示前2个
        
        return True
        
    except Exception as e:
        print(f"❌ 测试失败: {e}")
        import traceback
        traceback.print_exc()
        return False

if __name__ == "__main__":
    success = asyncio.run(test_final_fix())
    if success:
        print("\\n🎉 修复成功！现在可以正常使用大视频分析功能了。")
    else:
        print("\\n❌ 仍有问题，需要进一步调试。")